import { defineStore } from 'pinia';
import {reqSalesSort, reqSortVideo, reqVipZone} from "@/api/class/class";
import {ElMessage} from "element-plus";
interface LiveStateType{
    isHidden:boolean,
    selectList:any,
    sortList:any,
    isAddMore:boolean,
    isLoading:boolean
}
export const useLiveStore = defineStore('live',{
    state:():LiveStateType=>{
        return{
            isHidden:false,
            //选择区的数据
            selectList:[],
            //视频的综合排序
            sortList:[],
            //定义一个控制加载更多的界面
            isAddMore:true,
            //定义一个加载中的数据
            isLoading:false
        }
    },
    actions:{
        async getSelectList(){
            try {
                this.isLoading = true
                const result = await reqVipZone()
                this.isLoading = false
                this.selectList = result
            }catch (e){
                return Promise.reject(e)
            }
        },
        async getSortList(){
            try {
                this.isLoading = true
                const result = await reqSortVideo()
                this.isLoading = false
                this.sortList = result.content.content
            }catch (e){
                return Promise.reject(e)
            }
        },
        async getSalesSort(){
            try {
                this.isLoading = true
                const result = await reqSalesSort()
                this.isLoading = false
                this.sortList = result.content
            }catch (e){
                return Promise.reject(e)
            }
        },
        async AddMore(){
            try {
                const result = await reqSortVideo()
                this.sortList.push(...result.content.content)
                ElMessage.success("加载更多!")
                this.isAddMore = false
            }catch (e){
                return Promise.reject(e)
            }
        }
    },
})
